const DEFAULT_SITE_COOKIE_TAG = 'jy_esm_tag';

// 格式化 cookie 字符串
exports.formatCookieString = (cookieString = '') => {
    const cookieStringArray  = cookieString.split("; ");
    const cookies = {};
    cookieStringArray.forEach((item) => {
        if(item.includes('=')) {
            const splits = item.split('=');
            cookies[splits[0]] = splits[1];
        }else {
            cookies[item] = '';
        }
    });
    return cookies;
};

// 判断当前本网站的 cookie 是否存在
exports.isCookieExists = (cookies, tag = DEFAULT_SITE_COOKIE_TAG) => !!cookies[tag];

// 取 cookie
exports.getCookie = (cookies, tag = DEFAULT_SITE_COOKIE_TAG) => cookies[tag];